package charactor;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

/**
 * Created by MtRider on 2021/6/13 11:39
 */
public class TestLambda {
    public static void main(String[] args) {
        Random random = new Random();
        List<Hero> heroes = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            heroes.add(new Hero("hero" + i, random.nextInt(1000), random.nextInt(100)));
        }
        System.out.println("初始化后的集合：");
        System.out.println(heroes);
        System.out.println("筛选出 hp>100 && damange<50的英雄");
        filter(heroes,h->h.hp>100&&h.damage<50);
        /*HeroChecker checker = new HeroChecker() {
            @Override
            public boolean test(Hero h) {
                return (h.hp > 100 && h.damage < 50);
            }
        };
        filter(heroes, checker);*/
        HeroChecker checker =(Hero h)->{
            return h.hp>100&&h.damage<50 ;
        };
    }

    private static void filter(List<Hero> heroes, HeroChecker checker) {
        for (Hero hero : heroes) {
            if (checker.test(hero)) {
                System.out.print(hero);
            }
        }
    }
}
